<!-- 患者管理 -->
<template>
	<view class="Tatal ">
		<view class="Manage F"><text>患者管理</text></view>
		<wuc-tab class="list F" :tab-list="tabList" :tabCur.sync="TabCur" @change="tabChange"></wuc-tab>
		<view class="F" v-if="TabCur == 0" v-for="(item, index) in patientList" :key="index">
			<view class="list-view " @click="xingqing(item.id)">
				<image class="Ellipses" :src="item.headPortrait"></image>
				<text class="name">{{ item.name }}</text>
			</view>
		</view>
		<view class="F" v-if="TabCur == 1" v-for="(item, index) in patientChangeList" :key="index">
			<view class="list-view " @click="change(item.id)">
				<image class="Ellipses" :src="item.headPortrait"></image>
				<text class="name">{{ item.name }}</text>
				<text class="Leave">申请离院</text>
			</view>
		</view>
		<text class="loadMore">{{ contentText }}</text>

	</view>
</template>
<script>
	import WucTab from '@/components/wuc-tab/wuc-tab.vue';

	export default {
		components: {
			WucTab
		},
		data() {
			return {
				contentText: '上拉显示更多',
				pullFlag: true,
				fetchPageNum: 1,
				pageSize: 10,
				patientChangeList: [],
				refreshing: false,
				ind: 0,
				inde: 0,
				patientList: [],
				TabCur: 0,
				tabList: [{
					name: '患者列表'
				}, {
					name: '患者变更'
				}]
			};
		},
		onShow() {
			this.fetchPageNum = 1;
			this.pullFlag = true;
			this.refreshing = false;
			this.getData();
		},
		onReachBottom() {
			console.log('滑动到页面底部');
			this.contentText = '加载中...';
			if (this.pullFlag) {
				this.fetchPageNum += 1;
				this.pulllists();
			} else {
				this.contentText = '暂无更多数据';
			}
		},
		onPullDownRefresh() {
			uni.startPullDownRefresh({
				//API开始下拉刷新操作
				success: res => {
					this.refreshing = true;
					this.getData(); //下拉刷新重新获取数据
					uni.stopPullDownRefresh(); //API停止下拉刷
				}
			});

		},
		methods: {
			xingqing(id) {
				console.log(id);
				uni.navigateTo({
					url: '/pages/patientmanage/xiangqing?inde=' + id
				});
			},
			//下拉
			pulllists() {

				uni.request({
					url: this.$serverUrl + '/app/hospital/patient/patientList',
					data: {
						pageNumber: this.fetchPageNum, //当前页数
						pageSize: this.pageSize,
					},
					method: 'POST',
					header: {
						token: uni.getStorageSync('token'),
						'content-type': 'application/json',
						'content-type': 'application/x-www-form-urlencoded'
					},
					success: res => {
						console.log(res.data);
						// this.moneymanagerList = res.data.data;

						if (this.refreshing) {
							uni.showToast({
								title: '已经最新',
								icon: 'none'
							});
							this.refreshing = false;
							uni.stopPullDownRefresh();
							return;
						}
						let lists = [];
						let data = res.data.data;
						for (let i = 0; i < data.length; i++) {
							lists.push(data[i]);
						}
						if (lists.length < this.pageSize) {
							this.pullFlag = false;
						}
						// console.log('得到lists', lists);
						this.patientList = this.patientList.concat(lists);
						console.log('得到patientList', this.patientList);
					}
				});
				uni.request({
					url: this.$serverUrl + '/app/hospital/patient/patientChangeList',
					data: {
						pageNumber: this.fetchPageNum, //当前页数
						pageSize: this.pageSize
					},
					method: 'POST',
					header: {
						token: uni.getStorageSync('token'),
						'content-type': 'application/json',
						'content-type': 'application/x-www-form-urlencoded'
					},
					success: res => {
						console.log(res.data);
						if (this.refreshing) {
							uni.showToast({
								title: '已经最新',
								icon: 'none'
							});
							this.refreshing = false;
							uni.stopPullDownRefresh();
							return;
						}
						let lists = [];
						let data = res.data.data;
						for (let i = 0; i < data.length; i++) {
							lists.push(data[i]);
						}
						if (lists.length < this.pageSize) {
							this.pullFlag = false;
						}
						// console.log('得到lists', lists);
						this.patientChangeList = this.patientChangeList.concat(lists);
						console.log('得到patientChangeList', this.patientChangeList);

					}
				});

			},

			getData(e) {
				console.log(this.TabCur);
				uni.request({
					url: this.$serverUrl + '/app/hospital/patient/patientList',
					data: {
						pageNumber: 1, //当前页数
						pageSize: this.pageSize
					},
					method: 'POST',
					header: {
						token: uni.getStorageSync('token'),
						'content-type': 'application/json',
						'content-type': 'application/x-www-form-urlencoded'
					},
					success: res => {
						if (res.data.code == 0) {
							console.log(res.data);
							if (this.refreshing) {
								uni.showToast({
									title: '已经最新',
									icon: 'none'
								});
								this.refreshing = false;
								uni.stopPullDownRefresh();

								return;
							}
							let lists = [];
							let data = res.data.data;
							for (let i = 0; i < data.length; i++) {
								lists.push(data[i]);
							}
							if (lists.length < this.pageSize) {
								this.contentText = '暂无更多数据';
							}
							this.lists = res.data.data;
							console.log('得到lists', lists);
							if (this.refreshing) {
								this.refreshing = false;
								uni.stopPullDownRefresh();
								this.patientList = lists;
							} else {
								this.patientList = lists;
								console.info('this.fetchPageNum == ' + this.fetchPageNum);
								console.log('得到patientList', this.patientList);
							}
						}

					}
				});
				uni.request({
					url: this.$serverUrl + '/app/hospital/patient/patientChangeList',
					data: {
						pageNumber: 1, //当前页数
						pageSize: this.pageSize
					},
					method: 'POST',
					header: {
						token: uni.getStorageSync('token'),
						'content-type': 'application/json',
						'content-type': 'application/x-www-form-urlencoded'
					},
					success: res => {
						if (res.data.code == 0) {
							console.log(res.data);
							if (this.refreshing) {
								uni.showToast({
									title: '已经最新',
									icon: 'none'
								});
								this.refreshing = false;
								uni.stopPullDownRefresh();
								return;
							}
							let lists = [];
							let data = res.data.data;
							for (let i = 0; i < data.length; i++) {
								lists.push(data[i]);
							}
							if (lists.length < this.pageSize) {
								this.contentText = '暂无更多数据';
							}
							this.lists = res.data.data;
							// console.log('得到lists', lists);
							if (this.refreshing) {
								this.refreshing = false;
								uni.stopPullDownRefresh();
								this.patientChangeList = lists;
							} else {
								this.patientChangeList = lists;
								console.info('this.fetchPageNum == ' + this.fetchPageNum);
								console.log('得到this.patientChangeList', this.patientChangeList);
							}
						}
						// try {
						// 	uni.getStorageSync('data', JSON.stringify(res.data.data.token));
						// } catch (e) {}

					}
				});

			},
			tabChange(index) {
				var that = this;
				that.TabCur = index;
			},
			change(id) {
				console.log(id);
				uni.navigateTo({
					url: '/pages/patientmanage/Change?ind=' + id
				});
			},
			visibleChange(isShow) {
				// 列表框的显示隐藏事件
				console.log('isShow::', isShow);
			}
		}
	};
</script>

<style>
	page {
		background-color: #f8f8f8;
	}

	/* 整体 */
	.Tatal {
		/* margin-right: 30upx;
	margin-left: 30upx; */
	}

	/* 患者管理 */
	.Manage {
		padding-top: 60upx;
		padding-bottom: 60upx;
		padding-left: 30upx;
		font-size: 40upx;
	}

	.list {
		display: flex;
		flex-direction: column;
		padding-top: 40upx;
		padding-bottom: 40upx;
		margin: 10upx 0upx;
	}

	/* 循环 */
	.list-view {
		margin-top: 10upx;
		display: flex;
		flex-direction: row;
		height: 155upx;
		padding-left: 30upx;
		padding-right: 30upx;
	}

	.name {
		display: flex;
		align-items: center;
		margin-left: 30upx;
	}

	.Leave {
		display: flex;
		align-items: center;
		color: #0079c3;
		margin-left: auto;
	}

	.loadMore {
		font-size: 30upx;
		color: #555;
		margin-bottom: 20upx;
		margin: 0 auto;
	}
</style>
